package com.wc.alorithm_luogu.P1996;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Scanner;

/**
 * @Author congge
 * @Date 2023/5/14 18:31
 * @description https://www.luogu.com.cn/problem/P1996
 * 约瑟夫问题(循环链表)
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        LinkedList<Integer> linkedList = new LinkedList<>();

        for (int i = 1; i <= n; i++) {
            linkedList.add(i);
        }

        int curIndex = 1;

        ArrayList<Integer> ansArray = new ArrayList<>();
        while (!linkedList.isEmpty()) {
            Iterator<Integer> iterator = linkedList.iterator();

            while (iterator.hasNext()) {
                int curNum = iterator.next();
                if (curIndex == m) {
                    ansArray.add(curNum);
                    iterator.remove();
                    curIndex = 1;
                } else {
                    curIndex++;
                }
            }
        }
        StringBuilder ans = new StringBuilder();
        ans.append(ansArray.get(0));

        for (int i = 1; i < n; i++) {
            ans.append(' ');
            ans.append(ansArray.get(i));
        }

        System.out.println(ans);
    }
}
